﻿using Client.Todo.Common;
using Client.Todo.ViewModels;
using Client.Todo.ViewModels.Dialogs;
using Client.Todo.Views;
using Client.Todo.Views.Dialogs;
using Common.Lib.Service;
using DryIoc;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace Client.Todo
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainView>();
        }

        protected override void OnInitialized()
        {

            var dialog = Container.Resolve<IDialogService>();
            dialog.ShowDialog(nameof(LoginView), callback =>
            {
                if(callback.Result != ButtonResult.OK)
                {
                    Application.Current.Shutdown();
                    return;
                }
                var configService = App.Current.MainWindow.DataContext as IConfigureService;
                if (configService != null)
                {
                    configService.Configure();
                }
                base.OnInitialized();
            });

        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {

            containerRegistry.GetContainer().Register<HttpRestClient>(made:Parameters.Of.Type<string>(serviceKey:"webUrl"));
            containerRegistry.GetContainer().RegisterInstance(@"http://localhost:5133/", serviceKey: "webUrl");

            //注册服务
            containerRegistry.Register<ILoginService, LoginService>();
            containerRegistry.Register<IToDoService,ToDoService>();
            containerRegistry.Register<IMemoService, MemoService>();
            containerRegistry.Register<IDialogHostService, DialogHostService>();
            
            //注册Dialog
            containerRegistry.RegisterForNavigation<AddToDoView,AddToDoViewModel>(nameof(AddToDoView));
            containerRegistry.RegisterForNavigation<AddMemoView,AddMemoViewModel>(nameof(AddMemoView));
            containerRegistry.RegisterForNavigation<MessageView, MessageViewModel>(nameof(MessageView));


            containerRegistry.RegisterDialog<LoginView,LoginViewModel>();


            containerRegistry.RegisterForNavigation<IndexView>();
            containerRegistry.RegisterForNavigation<ToDoView>();
            containerRegistry.RegisterForNavigation<MemoView>();
            containerRegistry.RegisterForNavigation<SettingsView>();
            containerRegistry.RegisterForNavigation<SkinView>();
            containerRegistry.RegisterForNavigation<AboutView>();
            containerRegistry.RegisterForNavigation<SystemSettingsView>();
            //throw new NotImplementedException();
        }
    }
}
